import { Component, OnInit, Input, EventEmitter, Output, Host, Inject, forwardRef, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Service } from '../../../server/server';

import { RoleComponent } from '../role.component';
import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../public/serve/hints/hints.service';
declare var $: any;

interface Response {
  result: string[];
  result_code: string;
  message: string;
}

@Component({
  selector: 'app-role-delete',
  templateUrl: './role-delete.component.html',
})
export class RoleDeleteComponent implements OnInit {

  constructor(
    private http: HttpClient, 
    private server: Service, 
    private roleComponent: RoleComponent, 
    private removeTableService: RemoveTableService,
    private hintsService:HintsService
  ) { }

  ngOnInit() {

  }
  @Output()
  deleteOutput: EventEmitter<string> = new EventEmitter();
  //确认删除
  public confirmDel() {
    let body = {
      roleId: this.removeTableService.getRemoveTableId,
    }

    //console.log(body)
    this.http.post<Response>(this.server.baseUrl+'admin/roles/batchDelete', body).subscribe(res => {
      this.deleteOutput.emit(res.result_code);
      this.hintsService.messages(res.message,res.result_code);
      if (res.result_code == '0000') {

        $("#delete").modal("hide");
        this.removeTableService.getRemoveTableId = [];
      }
      else {
        //console.log('error');
        this.server.promptclose;
        $("#delete").modal("hide");
      }
    })
  }

}
